package com.sqx.modules.recovery.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.recovery.entity.GoodsRecovery;
import com.sqx.modules.recovery.service.GoodsRecoveryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description：TODO
 * @author： qiao
 * @create： 2024/6/28 16:02
 */
@RestController
@RequestMapping("/app/goodsRecovery")
@Api(value = "物品-用户端", tags = {"物品-用户端"})
public class AppGoodsRecoveryController {

    @Autowired
    private GoodsRecoveryService goodsRecoveryService;

    @PostMapping("/saveGoodsRecovery")
    @ApiOperation("添加物品")
    public Result saveGoodsRecovery(@ApiParam("物品实体") GoodsRecovery goodsRecovery) {
        return goodsRecoveryService.saveGoodsRecovery(goodsRecovery);
    }

    @PutMapping("/updateGoodsRecovery")
    @ApiOperation("修改物品")
    public Result updateGoodsRecovery(@ApiParam("物品实体") GoodsRecovery goodsRecovery) {
        return goodsRecoveryService.updateGoodsRecovery(goodsRecovery);
    }

    @PostMapping("/deleteGoodsRecovery")
    @ApiOperation("删除物品")
    public Result deleteGoodsRecovery(@ApiParam("物品id") Long id) {
        return goodsRecoveryService.deleteGoodsRecovery(id);
    }

    @Login
    @GetMapping("/estimatedPriceByRecoveryId")
    @ApiOperation("根据物品id获取详情")
    public Result estimatedPriceByRecoveryId(@ApiParam("物品id") @RequestParam(value = "recoveryId") Long recoveryId,
                                             @ApiParam("用户id") @RequestAttribute("userId") Long userId) {
        return goodsRecoveryService.estimatedPriceByRecoveryId(recoveryId, userId);
    }

    @Login
    @GetMapping("/selectListBySpecifications")
    @ApiOperation("获取回收规格列表")
    public Result selectListBySpecifications(@ApiParam("用户id") @RequestAttribute("userId") Long userId,
                                             @ApiParam("物品id") @RequestParam(value = "id") Long id) {
        return goodsRecoveryService.selectListBySpecifications(userId, id);
    }

    @GetMapping("/getGoodsRecoveryList")
    @ApiOperation("获取物品列表")
    public Result getGoodsRecoveryList(@ApiParam("页码") @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                       @ApiParam("条数") @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                       @ApiParam("物品名称") @RequestParam(value = "name", required = false) String name,
                                       @ApiParam("品牌id") @RequestParam(value = "brandId", required = false) Long brandId) {
        return goodsRecoveryService.getGoodsRecoveryListByBrandId(pageNum, pageSize, name, brandId);
    }

    @GetMapping("/getRecoveryListByBrandId")
    @ApiOperation("用户获取普通物品列表")
    public Result getGoodsRecoveryListByBrandId(@ApiParam("页码") @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                @ApiParam("条数") @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                @ApiParam("物品名称") @RequestParam(value = "name", required = false) String name,
                                                @ApiParam("品牌id") @RequestParam(value = "brandId", required = false) Long brandId) {
        return goodsRecoveryService.getRecoveryListByBrandId(pageNum, pageSize, name, brandId);
    }

}
